#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

bool zhibaohan07(int result){
    string resultStr = to_string(result);

    for(char c : resultStr){
        if(c != '0' && c != '7'){
            return false;
        }
    }
    return true;
}

int result07(int n){
    int m = 2;
    int result = n * m;
    while(!zhibaohan07(result)){
        ++m;
        result = n * m;    
    }
    return result;
}

bool StrPalindrome(string str){
    string str1 = str;
    reverse(str1.begin(), str1.end());
    return (str == str1);
}

int decimalToBinarConversion(int n){
   vector<int> array;
    do{
        array.push_back(n % 2);
    }while((n=n/2) != 0);
    

    int result;
    int r = 0;
    for(int i = array.size() - 1; i >= 0; --i){
        r = r * 10 + array[i];
    }
    return r;
}

vector<int> times07Fast(int n){
    int x = 0;
    vector<int> result;
    int i = 1;
    do{
        int binary_n = decimalToBinarConversion(i);
        x = binary_n * 7;
        ++i;
    }while(x % n != 0);
    if(StrPalindrome(to_string(x))){
        result.push_back(n);
        result.push_back(x);
    }
    else{
        result.push_back(n);
        result.push_back(0);
    }

    return result;
}

int main(int argc, char const *argv[])
{
    for(int i = 1; i <= 50; ++i){
        vector<int> array = times07Fast(i);
        for(int j = 0; j < 2; ++j){
            cout << array[j] << " ";
        }
        cout << endl;
    }
    return 0;
}
